class_name StateMachine
extends Node

@export var starting_state: State

var current_state: State

func init() -> void:
	change_state(starting_state)

func process_frame(delta: float) -> void:
	change_state(current_state.process_frame(delta))

func process_input(event: InputEvent) -> void:
	change_state(current_state.process_input(event))

func process_physics(delta: float) -> void:
	change_state(current_state.process_physics(delta))
	
func change_state(new_state: State) -> void:
	if !new_state:
		return

	if current_state:
		current_state.exit(new_state)
	current_state = new_state
	current_state.enter()
